from flask import Blueprint, request, jsonify
from app.services import StudyRecordService

bp = Blueprint('study_record', __name__)

@bp.route('', methods=['POST'])
def create_record():
    """提交学习记录"""
    data = request.get_json()
    result = StudyRecordService.create_record(
        student_id=data.get('student_id'),
        content_id=data.get('content_id'),
        study_type=data.get('study_type'),
        duration=data.get('duration'),
        score=data.get('score')
    )
    return jsonify(result), result['code']

@bp.route('/report', methods=['GET'])
def get_report():
    """获取学习报告"""
    student_id = request.args.get('student_id', type=int)
    result = StudyRecordService.get_learning_report(student_id)
    return jsonify(result), result['code']